# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

from jms_hi.dim.dim_yl_tmsnew_tms_in_warehouse_shi_base_dt import jms_dim__dim_yl_tmsnew_tms_in_warehouse_shi_base_dt
from jms_hi.dim.dim_yl_tms_cs_shift_base_dt import jms_dim__dim_yl_tms_cs_shift_base_dt
from jms_hi.dim.dim_yl_tmsnew_tms_transfer_shift_base_dt import jms_dim__dim_yl_tmsnew_tms_transfer_shift_base_dt
from jms_hi.dim.dim_yl_tmsnew_tms_out_warehouse_sh_base_dt import jms_dim__dim_yl_tmsnew_tms_out_warehouse_sh_base_dt
from jms_hi.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms_hi.dim.dim_tms_mainline_vehicleloading import jms_dim__dim_tms_mainline_vehicleloading
from jms_hi.dm.dm_waybill_simple_info_dt import jms_hi_dm__dm_waybill_simple_info_dt
from jms_hi.dm.dm_shipment_stop_billcode_detail_dt import jms_hi_dm__dm_shipment_stop_billcode_detail_dt
from jms_hi.dim.dim_tmsnew_vehicle_line import jms_dim__dim_tmsnew_vehicle_line
from jms_hi.dim.dim_yl_tms_branch_line_base_dt import jms_dim__dim_yl_tms_branch_line_base_dt

jms_hi_dm__dm_in_out_port_forecast_warning_summary_dt_in  = SparkSqlOperator(
    task_id='jms_hi_dm__dm_in_out_port_forecast_warning_summary_dt_in',
    email=['guoruiling@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_hi_dm__dm_in_out_port_forecast_warning_summary_dt_in_{{ execution_date | date_add(1) | cst_ds }}',
    pool_slots=1,
    retries=1,
    depends_on_past=True,
    driver_memory='4G',
    executor_memory='8G',
    executor_cores=4,
    num_executors=30,
    yarn_queue='pro',
    sql='jms_hi/dm/dm_in_out_port_forecast_warning_summary_dt_in/execute.sql',
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 36,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '4G',  # 堆外内存
          'spark.sql.shuffle.partitions': 280 ,
          'spark.default.parallelism': 280,
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=4 -XX:ConcGCThreads=2',
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 200,  # -表示一个动态分区语句可以创建的最大动态分区个数，超出报错
              'hive.exec.max.dynamic.partitions.pernode': 200,  # 默认100，一般可以设置大一点，比如1000。表示每个maper或reducer可以允许创建的最大动态分区个数，默认是100，超出则会报错。
              },
    execution_timeout = timedelta(minutes=60)
)

jms_hi_dm__dm_in_out_port_forecast_warning_summary_dt_in  << [
    jms_dim__dim_yl_tmsnew_tms_in_warehouse_shi_base_dt,
    jms_dim__dim_yl_tms_cs_shift_base_dt,
    jms_dim__dim_yl_tmsnew_tms_transfer_shift_base_dt,
    jms_dim__dim_yl_tmsnew_tms_out_warehouse_sh_base_dt,
    jms_dim__dim_network_whole_massage,
    jms_dim__dim_tms_mainline_vehicleloading,
    jms_hi_dm__dm_waybill_simple_info_dt,
    jms_hi_dm__dm_shipment_stop_billcode_detail_dt,
    jms_dim__dim_tmsnew_vehicle_line,
    jms_dim__dim_yl_tms_branch_line_base_dt,

]
 